<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>generator循环和调用</title>
</head>

<body>
  <script>
    function* foo() {
      yield 111
      yield 222
    }
    const g1 = foo()
    for (let item1 of g1) {
      console.log(item1)
    }
    // 调用foo,直接调用调不了,在yield前面加个*就可以调用了
    function* bar() {
      yield* foo()
      yield 333
      yield 444
    }
    const g2 = bar()
    console.log(g2)
    for (let item2 of g2) {
      console.log(item2)
    }
  </script>
</body>

</html>